package com.example.blogapi.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ReplaceUtils {

    public static String replaceAngleBrackets(String input) {
        String str = "(?<=```.+\\n)[\\s\\S]*?(?=```)";
        Pattern pattern = Pattern.compile(str);
        input = java.util.regex.Matcher.quoteReplacement(input);
        Matcher matcher = pattern.matcher(input);
        StringBuffer buffer = new StringBuffer();
        while (matcher.find()) {
            String code = matcher.group(0).replaceAll("<", "&lt;").replaceAll(">","&gt;");
            matcher.appendReplacement(buffer,code);
        }
        matcher.appendTail(buffer);
        String result = buffer.toString();
        return result;
    }
}
